/**
	
                 Springs On Rails
                 Copyright [2007] [Sunny Liu sunnyliu2@yahoo.com]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.	
*/
package org.springonrails.ant;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

import org.springonrails.appgen.SpringOnRails;




public class SpringOnRailsTask  extends Task
{
	private static Log log = LogFactory.getLog(SpringOnRailsTask.class);
	private String entityMappingLocation = null;
	private String outputPackageName = "com.asksunny.demo";
	private String outputPackageNameInFilePath = "com/asksunny/demo";	
	private String outputDir = "target";
	private String projectName= "demo";
	private String structureType = "maven";
	private String viewType = "both";	
	private String sqlStatementSeparator = ";";	
	private String dbType = "oracle";
	private String springVersion = "1";
	private String controllerType = "single";
	private String configLocation = null;
	
	
	//private Union resources = new Union();
	
	@Override
	public void execute() throws BuildException 
	{
		log.info("Begin of generating application skelton source files.");
		try{
			SpringOnRails rails = new SpringOnRails();
			rails.setArtifactId(this.projectName);
			rails.setGroupId(this.outputPackageName);
			rails.setOutputDir(this.outputDir);
			rails.setEntityMappingLocation(this.entityMappingLocation);
			rails.run();
		}catch(Exception ex){
			log.fatal("Fatal eroor occured while generating source.", ex);
			throw new BuildException("Failed to genrate rails Application", ex);
		}
		log.info("End of generating application skelton source files.");
	}

	private boolean isEmpty(String value)
	{
		
		return (value==null || value.trim().length()==0);
		
	}
	
	
	
	
	public String getControllerType() {
		return controllerType;
	}

	public void setControllerType(String controllerType) {
		this.controllerType = controllerType;
	}

	public String getConfigLocation() {
		return configLocation;
	}

	public void setConfigLocation(String configLocation) {
		this.configLocation = configLocation;
	}

	public String getDbType() {
		return dbType;
	}




	public void setDbType(String dbType) {
		this.dbType = dbType;
	}




	public String getSpringVersion() {
		return springVersion;
	}




	public void setSpringVersion(String springVersion) {
		this.springVersion = springVersion;
	}




	public String getEntityMappingLocation() {
		return entityMappingLocation;
	}
	public void setEntityMappingLocation(String entityMappingLocation) {
		this.entityMappingLocation = entityMappingLocation;
	}
	public String getOutputDir() {
		return outputDir;
	}
	public void setOutputDir(String outputDir) {
		this.outputDir = outputDir;
	}
	public String getOutputPackageName() {
		return outputPackageName;
	}
	public void setOutputPackageName(String outputPackageName) {
		this.outputPackageName = outputPackageName;
	}
	public String getOutputPackageNameInFilePath() {
		return outputPackageNameInFilePath;
	}
	public void setOutputPackageNameInFilePath(String outputPackageNameInFilePath) {
		this.outputPackageNameInFilePath = outputPackageNameInFilePath;
	}
	public String getProjectName() {
		return projectName;
	}
	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}
	public String getSqlStatementSeparator() {
		return sqlStatementSeparator;
	}
	public void setSqlStatementSeparator(String sqlStatementSeparator) {
		this.sqlStatementSeparator = sqlStatementSeparator;
	}
	public String getStructureType() {
		return structureType;
	}
	public void setStructureType(String structureType) {
		this.structureType = structureType;
	}
	public String getViewType() {
		return viewType;
	}
	public void setViewType(String viewType) {
		this.viewType = viewType;
	}
	
	
	
	
	
	
}
